package org.openkoala.demo.facade.impl.assembler;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import org.openkoala.demo.facade.dto.*;
import org.openkoala.demo.core.domain.*;

public class UserAssembler {
	
	public static UserDTO  toDTO(User  user){
		if (user == null) {
			return null;
		}
    	UserDTO result  = new UserDTO();
        result.setId (user.getId());
         result.setName (user.getName());
         result.setAge (user.getAge());
         result.setDept (user.getDept());
 	    return result;
	 }
	
	public static List<UserDTO>  toDTOs(Collection<User>  users){
		if (users == null) {
			return null;
		}
		List<UserDTO> results = new ArrayList<UserDTO>();
		for (User each : users) {
			results.add(toDTO(each));
		}
		return results;
	}
	
	 public static User  toEntity(UserDTO  userDTO){
	 	if (userDTO == null) {
			return null;
		}
	 	User result  = new User();
        result.setId (userDTO.getId());
         result.setName (userDTO.getName());
         result.setAge (userDTO.getAge());
         result.setDept (userDTO.getDept());
 	  	return result;
	 }
	
	public static List<User> toEntities(Collection<UserDTO> userDTOs) {
		if (userDTOs == null) {
			return null;
		}
		
		List<User> results = new ArrayList<User>();
		for (UserDTO each : userDTOs) {
			results.add(toEntity(each));
		}
		return results;
	}
}
